/**
 * Created by fanfz on 2016/8/2 0002.
 */
$(function () {
    $(".go_collect").click(function () {
        var gid=$(this).data('id');
        var uid=$("#session_user_id").val();
        if(uid=='')
        {
            alert('请先登录');
            window.location.href='index.php?a=login';
        }
        else
        {
            $.ajax({
                url:'index.php?a=go_collect',
                type:'post',
                data:{gid:gid,uid:uid},
                dataType:'json',
                success:function (data) {
                    if(data.status==1)
                    {
                        alert('收藏成功');
                    }
                    else if(data.status==-1)
                    {
                        alert('已收藏过了');
                    }
                    else
                    {
                        alert('网络异常');
                    }
                }
            })
        }
    });
    $(".cancel_collect").click(function () {
        var gid=$(this).data('gid');
        var collect_id=$(this).data('id');
        var uid=$("#session_user_id").val();
        if(uid=='')
        {
            alert('请先登录');
            window.location.href='index.php?a=login';
        }
        else {
            $.ajax({
                url: 'index.php?a=cancel_collect',
                type: 'post',
                data: {gid: gid, uid: uid, collect_id: collect_id},
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1) {
                        alert('取消收藏成功');
                        $("#collect_" + collect_id).remove();
                    }
                    else if (data.status == -1) {
                        alert('已取消');
                    }
                    else {
                        alert('网络异常');
                    }
                }
            })
        }
    });
    $("#code_img").click(function () {
        get_code();
    });
    function get_code() {
        $("#code_img").attr("src",'index.php?a=code&tm='+Math.random());
    }
    if($("#code_img").length>0)
    {
        get_code();
    }

});
